#include "helix.h"

#define kRadiusFlag			"-r"
#define kRadiusFlagLong		"-radius"
#define kPitchFlag			"-p"
#define kPitchFlagLong		"-pitch"
#define kCVNumberFlag		"-cvn"
#define kCVNumberFlagLong	"-cvnumber"

const char *kHelp =			"-h";
const char *kHelpLong =		"-help";

const char *helpText = 
"\n----------- \n\
use -r specify radius, \n\
use -p specify pitch, \n\
use -cvn specify cv number.\n\
-----------";

helix::helix()
{
}

helix::~helix()
{
}

MStatus helix::doIt(const MArgList& args)
{
	MStatus status;
	MArgDatabase argsdb(syntax(), args);
	
	if (argsdb.isFlagSet(kHelp))
	{
		MGlobal::displayInfo(helpText);
		return MS::kSuccess;
	}

	status = parseArgs(args);
	
	return status;
}

void* helix::creator()
{
	return new helix();
}

MSyntax helix::newSyntax()
{
	MSyntax helix_syntax;

	helix_syntax.addFlag(kRadiusFlag, kRadiusFlagLong, MSyntax::kDouble);
	helix_syntax.addFlag(kPitchFlag, kPitchFlagLong, MSyntax::kDouble);
	helix_syntax.addFlag(kCVNumberFlag, kCVNumberFlagLong, MSyntax::kUnsigned);
	helix_syntax.addFlag(kHelp, kHelpLong, MSyntax::kNoArg);

	return helix_syntax;
}

MStatus helix::parseArgs(const MArgList& args)
{
	MStatus status;
	MArgDatabase argdb(syntax(), args, &status);

	if (!status)
	{
		MGlobal::displayError("wrong number of syntax.");
		return status;
	}

	if (argdb.isFlagSet(kRadiusFlag))
	{
		double tmp;
		status = argdb.getFlagArgument(kRadiusFlag, 0, tmp);
		
		if (!status)
		{
			MGlobal::displayError("get radius wrong...");
			return status;
		}

		MGlobal::displayInfo(MString("get radius:") + tmp);
	}

	if (argdb.isFlagSet(kPitchFlag, &status))
	{
		double tmp;
		status = argdb.getFlagArgument(kPitchFlag, 0, tmp);
		
		if (!status)
		{
			MGlobal::displayError("get pitch wrong...");
			return status;
		}

		MGlobal::displayInfo(MString("get pitch:") + tmp);
	}

	if (argdb.isFlagSet(kCVNumberFlag, &status))
	{
		unsigned tmp;
		status = argdb.getFlagArgument(kCVNumberFlag, 0, tmp);

		if (!status)
		{
			MGlobal::displayError("get cv number wrong...");
			return status;
		}

		MGlobal::displayInfo(MString("get cv number:") + tmp);
	}
	    
	return MS::kSuccess;    
}
